package com.shenzhen.horselive.ui.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.User;
import com.shenzhen.horselive.adapter.ApplyCityHistoryAdapter;
import com.shenzhen.horselive.adapter.OpenHistoryAdapter;
import com.shenzhen.horselive.api.ApiFactory;
import com.shenzhen.horselive.base.AppBarActivity;
import com.shenzhen.horselive.beans.ApplyCityHistoryBean;
import com.shenzhen.horselive.beans.ApplyHistory;
import com.shenzhen.horselive.databinding.ActivityApplyCityHistoryBinding;
import com.shenzhen.horselive.network.SchedulersCompat;
import com.shenzhen.horselive.presenter.LoadingViewObserver;

import java.util.ArrayList;
import java.util.List;


public class ApplyCityHistoryActivity extends AppBarActivity {

    ActivityApplyCityHistoryBinding  binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding =  ActivityApplyCityHistoryBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setStyleDark();
        setTitle("申请历史");
        initViews();
//        initData();
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }

    private void initData() {
        ApiFactory.getApiService().applyCityHistory(User.get().getMyInfo().getToken())
                .compose(SchedulersCompat.applyIoSchedulers())
                .safeSubscribe(new LoadingViewObserver<ApplyCityHistoryBean>(this) {
                    @Override
                    protected void onNextInActive(ApplyCityHistoryBean applyHistory) {
                        if (applyHistory.isSuccess())
                        {
                            historyAdapter.setNewInstance(applyHistory.getData());

                        }else
                        {
                            showToast(applyHistory.getErrMessage());
                        }
                    }
                });

    }
    ApplyCityHistoryAdapter historyAdapter;
    private void initViews() {
        binding.recyclerview.setLayoutManager(new LinearLayoutManager(this));
       historyAdapter= new ApplyCityHistoryAdapter(R.layout.item_apply_city_history);
        binding.recyclerview.setAdapter(historyAdapter);
        historyAdapter.setEmptyView(R.layout.no_data_layout);
        historyAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
//              OpenCardDieatilsActivity.start(ApplyCityHistoryActivity.this,historyAdapter.getItem(position));
                ApplyCityDetailsActivity.start(ApplyCityHistoryActivity.this,historyAdapter.getItem(position));
            }
        });
    }
}